package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"
)

type CartAddNumLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartAddNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddNumLogic {
	return &CartAddNumLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 增加购物车中商品的数量
func (l *CartAddNumLogic) CartAddNum(in *homepage.CartAddNumRequest) (*homepage.CartAddNumResponse, error) {
	err := dao.CartIncreaseGoodsNum(int(in.UserId), int(in.GoodsId), int(in.SkuId))
	if err != nil {
		pkg.Error("增加数量失败", zap.Error(err))
		return nil, err
	}
	return &homepage.CartAddNumResponse{Msg: "增加数量成功"}, nil
}
